<?php

abstract class controller extends xpfw {

    protected $controller, $view, $bd, $layout;
    private $secure = false;

    function __construct($controller = '', $view = '') {
        $this->setController($controller);
        $this->setView($view);
        $this->isSecure();
    }

    private function isSecure() {
        $isSecure = $this->getSecure();
        if ($isSecure) {
            if (is_bool($isSecure) && !$this->getUser()->isAuthenticated())
                header('Location: ' . link_to('home/error403'));
            if (is_array($isSecure) && in_array($this->getView(), $isSecure) && !$this->getUser()->isAuthenticated())
                header('Location: ' . link_to('home/error403'));
        }
    }

    public function getController() {
        return $this->controller;
    }

    public function setController($controller) {
        $this->controller = $controller;
    }

    public function getViewPath() {
        return viewPath . $this->controller . '/' . $this->view . '.php';
    }

    public function getView() {
        return $this->view;
    }

    public function setView($view) {
        $this->view = $view;
    }

    public function redirect($url = '') {
        header('Location: ' . link_to($url));
        exit;
    }

    public function getSecure() {
        return $this->secure;
    }

    public function setSecure($secure) {
        $this->secure = $secure;
    }

    public function getLayout() {
        return $this->layout ? $this->layout : 'layout';
    }

    public function setLayout($layout) {
        $this->layout = $layout;
    }

}

?>
